<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>管理系统</title>
<#include "../inc/commonJs.html">
<script type="text/javascript">
	//定义冻结列
	var frozenColumns = [ [ {
		field : 'cddm',
		checkbox : true,
		colspan: 2 //兼容IE
	}] ];
	// 定义标题栏
	var columns = [ [  {
		field : 'cddm',
		title : '菜单代码',
		width : '80',
		align : 'center'
	}, {
		field : 'cdmc',
		title : '菜单名称',
		width : '120',
		align : 'center'
	}, {
		field : 'cdicon',
		title : '菜单图标',
		width : '120',
		align : 'center'
	}, {
		field : 'cdurl',
		title : '菜单链接',
		width : '160',
		align : 'left',
		align : 'center'
	}, {
		field : 'px',
		title : '排序',
		width : '40',
		align : 'center'
	}, {
		field : 'mxqx',
		title : '明细权限',
		width : '80',
		align : 'center',
		formatter:function(value,row,index){
			if(value != ''){
				return '有';
			}else{
				return '无';
			}
		}
	}, {
		field : 'cdcs',
		title : '菜单参数',
		width : '120',
		align : 'center',
		formatter:function(value,row,index){
			if(value != ''){
				return '有';
			}else{
				return '无';
			}
		}
	}, {
		field : 'zt',
		title : '状态',
		width : '50',
		align : 'center',
		formatter:function(value,row,index){
			if(value==1){
				return '启用';
			}else{
				return '禁用';
			}
		}
	  }
	]];
	//
	var grid;
	$(function(){
		grid = $('#grid').datagrid( {
			url : "selectCd.do",
			loadMsg : '数据加载中请稍后……',
			idField : 'cddm', 
			columns : columns,
			//frozenColumns : frozenColumns,
			//fitColumns:true,
			striped : true,
			singleSelect:true,
			rownumbers : true,
			pagination : true,
			toolbar : [btn_add,btn_edit,btn_del,"-"],
	        pageSize: [${syscfg.pageSize!10}],
	        pageList: [${syscfg.pageList!10}],
		});
		
		$('#cdtree').tree({
			url:'cdLeftTree.do',
		    lines:true,
		    animate:true,
		    onClick: function(node){
		    	$('#sjcd').val(node.id);
		    	grid.datagrid({
		    		url : "selectCd.do?sjcd="+node.id
		    	});
			}
		}); 
		
		$('#cdWindow').dialog({
	        title: '菜单信息设置',
	        width: 650,
	        modal: true,
	        shadow: true,
	        closed: true,
	        onClose:function(){
	        	$('#cdForm input').val('');
	        	$('#px').val('0');
	        	$('#zt').val('1');
	        },
	        buttons:[{
				text:'保存',
				iconCls:'icon-ok',
				handler:function(){
					$('#cdForm').form('submit', {  
					    url:'saveCd.do',
					    onSubmit: function(param){
					    	return $(this).form('validate');
					    },
					    success:function(data){
					    	$('#cdForm').form('clear');
					    	$("#cdWindow").dialog('close');
					    	$('#cdtree').tree('reload');
					    	grid.datagrid('reload');
					    	top.messagershow(data);
					    }    
					}); 
				}
			},{
				text:'关闭',
				iconCls:'icon-cancel',
				handler:function(){
					$('#cdForm').form('clear');
					$("#cdWindow").dialog('close');
				}
			}]
	    });
		
	});
	//
	function doAdd() {
    	$('#action').val('1');
		$('#cddm').removeAttr('readonly');
		$("#cdWindow").dialog('open').dialog('center');
	}

	function doEdit() {
		var item = grid.datagrid('getSelected');
		if(item != null) {
	    	$('#action').val('0');
			$('#cddm').attr('readonly','readonly');
			$('#cdForm').form('load','selectOneCd.do?cddm='+item.cddm);
			$("#cdWindow").dialog('open').dialog('center');
		}else{
			$.messager.alert("信息提示","请选择相关数据进行操作！","error");
		}
	}

	function doDel() {
		var item = grid.datagrid('getSelected');
		if(item == null){
			$.messager.alert("信息提示","请选择相关数据进行操作！","error");
			return ;
		}
		$.messager.confirm("操作提示", "删除菜单！",function(r){
			if(r){
				 $.post("delCd.do", {cddm :item.cddm}, function(data){
					 if(data){
							top.messagershow(data);
							$("#grid").datagrid('reload');
							$('#cdtree').tree('reload');
							//grid.datagrid('uncheckAll'); // 取消所有元素选中效果
						}
				});  
			}
		});
	}
</script>	
</head>
<body>
<div align="center" class="easyui-panel" data-options='fit:true,border:false'>
<div class="easyui-layout" data-options="fit:true">
	<div data-options="region:'west',iconCls:'icon-mini-add',title:'菜单目录',border:true,split:true" style="width: 180px;">
		<ul id="cdtree" class="easyui-tree"></ul>  
	</div>
	<div region="center" border="false">
		<table id="grid" data-options="fit:true,border:false"></table>
	</div>
	<!-- 窗口 -->
	<div  id="cdWindow" style="display:">
		<form id="cdForm" method="post">
		<input type="hidden" class="easyui-validatebox" name="action" id="action" value="0">
			<table class="table_all" width="98%" align="center" border="0"  cellspacing="0" cellpadding="0">
				<tr>
					<td class="td_table_1" width="150">菜单代码:</td>
					<td class="td_table_2"><input class="easyui-validatebox" type="text" id="cddm" name="cddm" data-options="required:true"/></td>
					<td class="td_table_1" width="150">菜单名称:</td>
					<td class="td_table_2"><input class="easyui-validatebox" type="text" id="cdmc" name="cdmc" data-options="required:true"/></td>
				</tr>
				<tr>
					<td class="td_table_1">菜单图标:</td>
					<td class="td_table_2"><input class="easyui-validatebox" type="text" id="cdicon" name="cdicon"/></td>
					<td class="td_table_1">菜单链接:</td>
					<td class="td_table_2"><input class="easyui-validatebox" type="text" id="cdurl" name="cdurl" size="40"/></td>
				</tr>
				<tr>
					<td class="td_table_1">上级菜单:</td>
					<td class="td_table_2"><input class="easyui-validatebox" type="text" id="sjcd" name="sjcd" /></td>
					<td class="td_table_1">菜单参数:</td>
					<td class="td_table_2"><input class="easyui-validatebox" type="text" id="cdcs" name="cdcs" size="40"/></td>
				</tr>
				<tr>
					<td class="td_table_1">排序:</td>
					<td class="td_table_2"><input class="easyui-validatebox" type="text" id="px" name="px" value="0"/></td>
					<td class="td_table_1">状态:</td>
					<td class="td_table_2"><input class="easyui-validatebox" type="text" id="zt" name="zt" value="1"/></td>
				</tr>
			</table>
		</form>
	</div>
</div>
</div>
</body>
</html>